<?php echo $this->Html->script('Album.GTab')?>
<!-- album -->
<?php 
	Global $dialogIdstr;
	Global $timer;
	if (isset($dialogIdstr)) {
		$timer = $timer+1;
		$dialogIdstr = 'dialogid'.$timer;
	}else{
		$timer = time();
		$dialogIdstr = 'dialogid'.$timer;
	}
	if(isset($pluginid))$dialogIdstr = 'dialogid'.$pluginid;
	$album_id = isset($album_id)?$album_id:false;
?>
<?php $albumList = null;//$this->requestAction(array('admin'=>false,'plugin'=>'album','controller'=>'Albums','action'=>'albumListOption'));?>
<div id="<?php echo $dialogIdstr?>" class = 'switch_dialog' style = 'display:none'>
	<?php if ((isset($upload) && $upload)&&(isset($list) && $list)) :?>
	<ul class="tab_handel">
			<li><a href="javascript:;">上传图片</a></li>
			<li><a href="javascript:;">相册图片</a></li>
	</ul>
	<?php endif;?>
	<?php if (isset($upload) && $upload){
		echo $this->element('Album.albumUpload',array('id_pre'=>$dialogIdstr,'album_id'=>$album_id,'albumList'=>$albumList));
	}?>
	<?php if (isset($list) && $list){
		echo $this->element('Album.albumList',array('id_pre'=>$dialogIdstr,'album_id'=>$album_id,'albumList'=>$albumList));
	}?>
</div>
<input id = '<?php echo $dialogIdstr.'_btn'?>' type = button onclick ="<?php echo $dialogIdstr.'.openDialog()'?>" value="<?php echo isset($text)?$text:'浏览'?>"/>
<?php 
$scriptRoot = "var $dialogIdstr = {};"; 
$callDialogCreat = "$dialogIdstr.dialogCreate()";
$callDialogOpen = "$dialogIdstr.openDialog()";
$callDialogClose = "$dialogIdstr.closeDialog()";
$callback = "$dialogIdstr.dialogCallback()";
$dialogCreat = "$dialogIdstr.dialogCreate = function(){
	$(\"#$dialogIdstr\").dialog({
		width: 510,
		height: 420,
		modal: true,
		autoOpen:false,
		resizable:false,
		buttons:[{
			text: \"确定\",
			click: $dialogIdstr.selectPic
		},{
			text: \"取消\",
			click: $dialogIdstr.closeDialog
		}]
	})
};";
$dialogOpen = "$dialogIdstr.openDialog = function(){
	$(\"#$dialogIdstr\").dialog(\"open\");
};";

$dialogClose = "$dialogIdstr.closeDialog = function(){
	$(\"#$dialogIdstr\").dialog(\"close\");
	jQuery('#".$dialogIdstr."_up_form .preivew').hide()
};";
$dialogPicSelect = "$dialogIdstr.selectPic = function(){
	var data = {};
	data.pic_id =  jQuery('#$dialogIdstr .pic_id').val();
	data.pic_link = jQuery('#$dialogIdstr .pic_link').val();
	data.ext = jQuery('#$dialogIdstr .pic_ext').val();
	if(data.pic_id>0){
		$dialogIdstr.dialogCallback(data);
		$callDialogClose;
	}else{
		GM.tip('请先上传一张图片',false);
	}
};";
if (isset($userCallback)) {
	$dcallback = $userCallback.'(data)';
}else{
	$dcallback = "GM.tip('please override callback function '+data.pic_id,false);";
}
$dialogCallback = "$dialogIdstr.dialogCallback = function(data){
	$dcallback
};";
?>
<script type="text/javascript">
jQuery().ready(function(){
	jQuery('#<?php echo $dialogIdstr?>').GTab();
<?php echo "\t".$callDialogCreat; ?>	
});
<?php 
echo $scriptRoot."\n";
echo $dialogCreat."\n";
echo $dialogOpen."\n";
echo $dialogClose."\n";
echo $dialogCallback."\n";
echo $dialogPicSelect."\n";
?>
</script>
<style type="text/css">
.switch_dialog .tab_handel{
	height:25px;
}
.switch_dialog .tab_handel li{
	float:left;
}
</style>